<?php 
class ConnDB{
	private $conn;
	public function __construct($host,$user,$pwd,$dbname,$charset){
		$this->conn = @mysql_connect($host,$user,$pwd) or die('数据库连接失败！'.mysql_error());
		//选择数据库
		@mysql_set_charset($charset);
		@mysql_select_db($dbname) or die('数据库不存在！'.mysql_error());

	}
	//执行sql语句，如果是select语句，就返回查询结果集数组，否则返回true或false，
	function query($sql){	
		$sqltype = strtolower(substr(trim($sql),0,6));
		$result = mysql_query($sql,$this->conn) or die('查询失败'.mysql_error());
		//定义二维数组用于存储select语句的查询结果
		$callback_array = array();
		//判断sql语句的类型，如果是select语句
		if("select" == $sqltype){
			//如果select
			if($result == false){
				return false;

			} else if(0 == mysql_num_rows($result)){
				return false;
			} 
			/*else if(1 == mysql_num_rows($result)){
				return mysql_fetch_array($result);
			} */
			else 
				while ($result_array = mysql_fetch_array($result)){
					array_push($callback_array,$result_array);

				}
				return $callback_array;

	}
	    else if('update' == $sqltype || 'insert' == $sqltype || 'delete' == $sqltype){
	    	return $result;
	}

	}
	function __destruct(){
		mysql_close($this->conn);
	}


}




 ?>